﻿using System;
using System.Windows;
using System.Windows.Input;

public class RoutedCommand : ICommand
{
    private readonly Func<object,bool> _canExecute;
    private readonly Action<object,UIElement> _execute;

    public RoutedCommand(
        Action<object,UIElement> execute,
        Func<object,bool> canExectute)
    {
        _execute = execute;
        _canExecute = canExectute;
    }

    public RoutedCommand(Action<object,UIElement> execute)
        : this(execute, _ => true)
    {
    }

    public bool CanExecute(object parameter)
    {
        return _canExecute(parameter);
    }

    public event EventHandler CanExecuteChanged
    {
        add { }
        remove { }
    }

    public void Execute(object parameter)
    {
        _execute(parameter, null);
    }

    public void Execute(object parameter, UIElement target)
    {
        _execute(parameter, target);
    }
}

